package com.qiyi.player.wonder.plugins.scenetile.view
{
   import com.iqiyi.components.panelSystem.impls.BasePanel;
   import com.qiyi.player.wonder.common.status.Status;
   import com.qiyi.player.wonder.common.vo.UserInfoVO;
   import common.CommonBg;
   import common.CommonCloseBtn;
   import com.qiyi.player.wonder.common.ui.SelectTextField;
   import com.qiyi.player.wonder.plugins.scenetile.view.greentailpart.TunkVersionPanel;
   import com.qiyi.player.wonder.plugins.scenetile.view.greentailpart.SoundVersionPanel;
   import com.qiyi.player.wonder.plugins.scenetile.SceneTileDef;
   import flash.events.MouseEvent;
   import flash.net.navigateToURL;
   import flash.net.URLRequest;
   import com.qiyi.player.wonder.common.config.SystemConfig;
   import com.iqiyi.components.global.GlobalStage;
   import flash.display.DisplayObjectContainer;
   import gs.TweenLite;
   import com.qiyi.player.wonder.body.BodyDef;
   import flash.events.Event;
   
   public class SceneTileGreenTailView extends BasePanel
   {
      
      public function SceneTileGreenTailView(param1:DisplayObjectContainer, param2:Status, param3:UserInfoVO) {
         super(NAME,param1);
         type = BodyDef.VIEW_TYPE_POPUP;
         this._status = param2;
         this._userInfoVO = param3;
         this.initUI();
      }
      
      public static const NAME:String = "com.qiyi.player.wonder.plugins.scenetile.view.SceneTileGreenTailView";
      
      private var _status:Status;
      
      private var _userInfoVO:UserInfoVO;
      
      private var _bg:CommonBg;
      
      private var _closeBtn:CommonCloseBtn;
      
      private var _versionTagVec:Vector.<SelectTextField>;
      
      private var _currSelectItem:SelectTextField;
      
      private var _tunkPanel:TunkVersionPanel;
      
      private var _soundPanel:SoundVersionPanel;
      
      public function get currSelectItem() : SelectTextField {
         return this._currSelectItem;
      }
      
      public function get isPair() : Boolean {
         return this._tunkPanel?this._tunkPanel.isPair:false;
      }
      
      private function initUI() : void {
         var _loc2_:SelectTextField = null;
         this._bg = new CommonBg();
         this._bg.width = SceneTileDef.PANEL_WIDTH;
         this._bg.height = SceneTileDef.PANEL_HEIGHT_INIT;
         addChild(this._bg);
         this._versionTagVec = new Vector.<SelectTextField>();
         var _loc1_:uint = 20;
         var _loc3_:uint = 0;
         while(_loc3_ < SceneTileDef.VERSION_VECTOR.length)
         {
            _loc2_ = new SelectTextField(SceneTileDef.VERSION_VECTOR[_loc3_]);
            if(_loc3_ == 0)
            {
               this._currSelectItem = _loc2_;
               _loc2_.isSelected = true;
            }
            _loc2_.data = SceneTileDef.VERSION_VECTOR[_loc3_];
            _loc2_.x = _loc1_;
            _loc2_.y = 10;
            _loc1_ = _loc1_ + _loc2_.width + 10;
            addChild(_loc2_);
            this._versionTagVec.push(_loc2_);
            _loc2_.addEventListener(MouseEvent.CLICK,this.onSelectItemClick);
            _loc3_++;
         }
         this._closeBtn = new CommonCloseBtn();
         this._closeBtn.x = this._bg.width - this._closeBtn.width - 5;
         this._closeBtn.y = 1;
         addChild(this._closeBtn);
         this._soundPanel = new SoundVersionPanel();
         this._soundPanel.y = 35;
         addChild(this._soundPanel);
         this._tunkPanel = new TunkVersionPanel();
         this._tunkPanel.y = 35;
         addChild(this._tunkPanel);
         if(this._currSelectItem.data == SceneTileDef.VERSION_VECTOR[0])
         {
            this._soundPanel.openPanel();
            this._tunkPanel.closePanel();
         }
         else
         {
            this._soundPanel.closePanel();
            this._tunkPanel.openPanel();
         }
         this._tunkPanel.addEventListener(SceneTileEvent.Evt_PanelHeightChange,this.onPanelHeightChange);
         this._tunkPanel.addEventListener(SceneTileEvent.Evt_LinkTextClick,this.onLinkTextClick);
         this._tunkPanel.addEventListener(SceneTileEvent.Evt_ReturnLookBtnClick,this.onCloseBtnClick);
         this._tunkPanel.addEventListener(SceneTileEvent.Evt_GreenTailClose,this.onCloseBtnClick);
         this._soundPanel.addEventListener(SceneTileEvent.Evt_SendBtnClick,this.onSendBtnClick);
         this._soundPanel.addEventListener(SceneTileEvent.Evt_GreenTailClose,this.onCloseBtnClick);
         this._soundPanel.addEventListener(SceneTileEvent.Evt_PanelHeightChange,this.onPanelHeightChange);
         this._soundPanel.addEventListener(SceneTileEvent.Evt_LinkTextClick,this.onLinkTextClick);
         this._soundPanel.addEventListener(SceneTileEvent.Evt_ReturnLookBtnClick,this.onCloseBtnClick);
         this._closeBtn.addEventListener(MouseEvent.CLICK,this.onCloseBtnClick);
      }
      
      private function onLinkTextClick(param1:SceneTileEvent) : void {
         dispatchEvent(new SceneTileEvent(SceneTileEvent.Evt_GreenTailClickLink));
         navigateToURL(new URLRequest(SystemConfig.APP_DOWNLOAD_URL),"_blank");
      }
      
      private function onPanelHeightChange(param1:SceneTileEvent) : void {
         this._bg.height = int(param1.data);
         this.onResize(GlobalStage.stage.stageWidth,GlobalStage.stage.stageHeight);
      }
      
      public function onAddStatus(param1:int) : void {
         var _loc2_:uint = 0;
         this._status.addStatus(param1);
         switch(param1)
         {
            case SceneTileDef.STATUS_GREEN_TAIL_OPEN:
               this._currSelectItem = this._versionTagVec[0];
               this._soundPanel.openPanel();
               this._tunkPanel.closePanel();
               _loc2_ = 0;
               while(_loc2_ < this._versionTagVec.length)
               {
                  this._versionTagVec[_loc2_].isSelected = false;
                  if(_loc2_ == 0)
                  {
                     this._versionTagVec[_loc2_].isSelected = true;
                  }
                  _loc2_++;
               }
               this.open();
               break;
         }
      }
      
      public function onRemoveStatus(param1:int) : void {
         this._status.removeStatus(param1);
         switch(param1)
         {
            case SceneTileDef.STATUS_GREEN_TAIL_OPEN:
               this._soundPanel.closePanel();
               this._tunkPanel.closePanel();
               this.close();
               break;
         }
      }
      
      public function onResize(param1:int, param2:int) : void {
         if(isOnStage)
         {
            x = (param1 - this._bg.width) / 2;
            y = (param2 - this._bg.height) / 2;
            if(y < 0)
            {
               y = 0;
            }
         }
      }
      
      public function onUserInfoChanged(param1:UserInfoVO) : void {
         this._userInfoVO = param1;
      }
      
      override public function open(param1:DisplayObjectContainer = null) : void {
         if(!isOnStage)
         {
            super.open(param1);
            dispatchEvent(new SceneTileEvent(SceneTileEvent.Evt_GreenTailOpen));
         }
      }
      
      override public function close() : void {
         if(isOnStage)
         {
            super.close();
            dispatchEvent(new SceneTileEvent(SceneTileEvent.Evt_GreenTailClose));
         }
      }
      
      override protected function onAddToStage() : void {
         super.onAddToStage();
         this.onResize(GlobalStage.stage.stageWidth,GlobalStage.stage.stageHeight);
         alpha = 0;
         TweenLite.to(this,BodyDef.POPUP_TWEEN_TIME / 1000,{"alpha":1});
      }
      
      override protected function onRemoveFromStage() : void {
         super.onRemoveFromStage();
         TweenLite.killTweensOf(this);
      }
      
      public function requestDataEvent(param1:String, param2:String, param3:int, param4:String, param5:String) : void {
         if(this._currSelectItem.data == SceneTileDef.VERSION_VECTOR[0])
         {
            this._soundPanel.requestBlankEvent(param1,param2,param3,param4,param5);
         }
         else if(this._currSelectItem.data == SceneTileDef.VERSION_VECTOR[1])
         {
            this._tunkPanel.requestBlankEvent(param1,param2,param3,param4,param5);
         }
         
      }
      
      public function setDataForSoundVersion(param1:String, param2:String, param3:int, param4:String, param5:String) : void {
      }
      
      private function onSelectItemClick(param1:MouseEvent) : void {
         var _loc3_:SelectTextField = null;
         var _loc2_:SelectTextField = param1.currentTarget as SelectTextField;
         if(this._currSelectItem == _loc2_)
         {
            return;
         }
         for each(_loc3_ in this._versionTagVec)
         {
            _loc3_.isSelected = false;
            if(_loc3_ == _loc2_)
            {
               _loc3_.isSelected = true;
               this._currSelectItem = _loc3_;
               if(this._currSelectItem.data == SceneTileDef.VERSION_VECTOR[0])
               {
                  this._soundPanel.openPanel();
                  this._tunkPanel.closePanel();
               }
               else
               {
                  this._soundPanel.closePanel();
                  this._tunkPanel.openPanel();
               }
            }
         }
      }
      
      private function onSendBtnClick(param1:SceneTileEvent) : void {
         dispatchEvent(new SceneTileEvent(SceneTileEvent.Evt_SendBtnClick));
      }
      
      private function onCloseBtnClick(param1:Event) : void {
         this.close();
      }
   }
}
